//
//  WXPOrderDetailFooterView.m
//  MexicoLoan
//
//  Created by wxp on 2025/3/18.
//

#import "WXPOrderDetailFooterView.h"

@implementation WXPOrderDetailFooterView

#pragma mark - lazy
- (UIView *)viewBack{
    if (!_viewBack) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.width = SCREEN_WIDTH-LEFT_MARDIN*2;
    }
    return _viewBack;
}
- (UILabel *)labelTitle{
    if (!_labelTitle) {
        _labelTitle = [UILabel new];
        [GlobalMethod setLabel:_labelTitle widthLimit:0 isBold:true fontNum:16 textColor:COLOR_BLACK text:@"Detalles del préstam"];
    }
    return _labelTitle;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = COLOR_LINE;
        _lineView.widthHeight = XY(SCREEN_WIDTH-LEFT_MARDIN*4, 1);
    }
    return _lineView;
}
- (UIView *)viewContent{
    if (!_viewContent) {
        _viewContent = [UIView new];
        _viewContent.backgroundColor = [UIColor clearColor];
        _viewContent.widthHeight = XY(self.viewBack.width, 0);
    }
    return _viewContent;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, 0);
        self.backgroundColor = [UIColor clearColor];
        [self addSubView];
    }
    return self;
}

- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.labelTitle];
    [self.viewBack addSubview:self.lineView];
    [self.viewBack addSubview:self.viewContent];
    [self resetView:nil];
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    switch (sender.tag) {
        case 1:
        {
            // 协议
            sender.selected = !sender.selected;
        }
            break;
        case 3: // 登录
        {
//            if(self.blockClick){
//                self.blockClick(sender.tag);
//            }
        }
            break;
        default:
            break;
    }
}

#pragma mark - 刷新View
- (void)resetView:(NSArray *)list{
    self.labelTitle.leftTop = XY(LEFT_MARDIN, LEFT_MARDIN);
    self.lineView.leftTop = XY(self.labelTitle.left, self.labelTitle.bottom+LEFT_MARDIN);
    
    self.viewContent.height = 0;
    if(isAry(list)){
        CGFloat topMark = LEFT_MARDIN;
        [self.viewContent removeAllSubViews];
        for (int i = 0; i < list.count; i ++) {
            ModelPairs * model = list[i];
            UILabel * labelLeft = [UILabel new];
            [GlobalMethod setLabel:labelLeft widthLimit:0 fontNum:12 textColor:COLOR_CONTENT text:readStr(model.key)];
            labelLeft.leftTop = XY(LEFT_MARDIN, topMark);
            [self.viewContent addSubview:labelLeft];
            topMark = labelLeft.bottom+LEFT_MARDIN*2;
            UILabel * labelRight = [UILabel new];
            [GlobalMethod setLabel:labelRight widthLimit:0 isBold:true fontNum:14 textColor:COLOR_BLACK text:readStr(model.value)];
            labelRight.rightCenterY = XY(self.viewContent.width-LEFT_MARDIN, labelLeft.centerY);
            [self.viewContent addSubview:labelRight];
        }
        self.viewContent.height = topMark;
    }
    self.viewContent.leftTop = XY(0, self.lineView.bottom+9);
    self.viewBack.height = self.viewContent.bottom;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.viewBack.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(16, 16)];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.path = path.CGPath;
    self.viewBack.layer.mask = maskLayer;
    self.viewBack.centerXTop = XY(self.width/2, 0);
    
    self.height = self.viewBack.bottom+LEFT_MARDIN;
}

@end
